import uuid from "../../utils/uuid";


Page({
  data: {
    money: 32,
    signStatus: false,
    noticeList: [1, 2, 3],
    orderList: [],
    bubbleList: [
      {
        key: uuid(),
        top: '65px',
        show: true,
        animation: false
      },
      {
        key: uuid(),
        top: '25px',
        show: true,
        animation: false
      },
      {
        key: uuid(),
        top: '45px',
        show: true,
        animation: false
      },
      {
        key: uuid(),
        top: '25px',
        show: true,
        animation: false
      },
      {
        key: uuid(),
        top: '65px',
        show: true,
        animation: false
      }
    ],
    taskPanelRef: null
  },

  gotoMessage() {
    my.navigateTo({ url: '../../pages/message/message' })
  },

  onBubbleClick(e: any) {
    const { key } = e.target.dataset;

    this.setData({
      money: this.data.money + 2,
      bubbleList: this.data.bubbleList.map((item: any) => {
        if (item.key === key) {
          item.animation = true
        }
        return item
      })
    })

    setTimeout(() => {
      this.setData({
        bubbleList: this.data.bubbleList.map((item: any) => {
          if (item.key === key) {
            item.show = false
          }
          return item
        })
      })
    }, 2000)
  },

  signIn() {
    if (this.data.signStatus) return
    this.setData({
      signStatus: true,
      money: this.data.money + 2
    })
    my.showToast({
      content: '签到成功',
      type: 'success',
      duration: 1000
    })
  },

  showTaskPanel() {
    this.data.taskPanelRef.show()
  },

  handleRef(ref) {
    this.setData({
      taskPanelRef: ref
    })
  },
});